﻿
// AJAX foundation class
function AJAX() {
    this.xmlHttp = this.getXmlHttpRequest();
    this._statechange.parent = this;
}

AJAX.prototype.getXmlHttpRequest = function () {
    if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
}

AJAX.prototype.start = function (url, func, owner) {
    var that = this;
    this.xmlHttp.onreadystatechange = function () {
        that._statechange(that);
    }
    this._handledata = func;
    this._handleowner = owner;

    this.xmlHttp.open("GET", url, true);
    this.xmlHttp.send(null);
}

AJAX.prototype._statechange = function (ins) {
    if (ins.xmlHttp.readyState == 4) {
        if (ins.xmlHttp.status == 200) {
            var data = ins.xmlHttp.responseXml;
            if (ins._handledata) {
                if (ins._handleowner) {
                    ins._handledata.call(ins._handleowner, data);
                }
                else {
                    ins._handledata.call(window, data);
                }
            }
        }
    }
}